<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="80px"
    >
      <el-form-item label="手机号" prop="userPhonenumber">
        <el-input
          v-model="queryParams.userPhonenumber"
          placeholder="请输入用户手机号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="预约时间">
        <el-date-picker
          v-model="daterangeAppointTime"
          style="width: 240px"
          value-format="yyyy-MM-dd HH:mm:ss"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          :default-time="['00:00:00', '23:59:59']"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="小区名称" prop="cellName">
        <el-input
          v-model="queryParams.cellName"
          placeholder="请输入小区名称"
          clearable
        />
      </el-form-item>
      <el-form-item label="技师名称" prop="technicianName">
        <el-input
          v-model="queryParams.technicianName"
          placeholder="请输入技师名称"
          clearable
        /> </el-form-item
      ><el-form-item label="订单号" prop="id">
        <el-input
          v-model="queryParams.id"
          placeholder="请输入订单号"
          clearable
        />
      </el-form-item>
      <el-form-item label="订单状态" prop="status">
        <el-select
          v-model="queryParams.status"
          placeholder="请选择订单状态"
          clearable
        >
          <el-option
            v-for="dict in dict.type.srv_order_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['service:orderManagement:export']"
          >导出</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
        :columns="columns"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="orderManagementList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column
        v-if="columns[0].visible"
        label="订单编号"
        align="center"
        prop="id"
      />
      <!--      <el-table-column label="用户id" align="center" prop="userId" />-->
      <el-table-column
        v-if="columns[1].visible"
        label="用户手机号"
        align="center"
        prop="userPhonenumber"
      />
      <!--      <el-table-column label="所属区域id" align="center" prop="deptId" />-->
      <el-table-column
        v-if="columns[2].visible"
        label="车辆信息"
        align="center"
        prop="carNo"
      >
        <template slot-scope="scope">
          {{ scope.row.carColor }} <br />{{ scope.row.carBarnd }}<br />
          {{ scope.row.carNo }}
        </template>
      </el-table-column>
      <el-table-column
        v-if="columns[3].visible"
        label="预约时间"
        align="center"
        prop="appointTime"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.appointTime, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column
        v-if="columns[4].visible"
        label="支付方式"
        align="center"
        prop="payTypeName"
      />
      <el-table-column
        v-if="columns[5].visible"
        label="支付价格"
        align="center"
        prop="payPrice"
      />
      <el-table-column
        v-if="columns[6].visible"
        label="服务名称"
        align="center"
        prop="serveName"
      />
      <el-table-column
        v-if="columns[7].visible"
        label="小哥名称"
        align="center"
        prop="technicianName"
      />
      <el-table-column
        v-if="columns[8].visible"
        label="下单时间"
        align="center"
        prop="createTime"
      />
      <el-table-column
        v-if="columns[9].visible"
        label="订单状态"
        align="center"
        prop="status"
      >
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.srv_order_status"
            :value="scope.row.status"
          />
        </template>
      </el-table-column>
      <el-table-column
        v-if="columns[10].visible"
        label="小区名称"
        align="center"
        prop="cellName"
      />
      <el-table-column
        v-if="columns[11].visible"
        label="我方备注"
        align="center"
        prop="ourRemark"
      />
      <el-table-column
        v-if="columns[12].visible"
        label="备注"
        align="center"
        prop="remark"
      />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            v-if="scope.row.status === '2'"
            @click="handleDistribution(scope.row)"
            v-hasPermi="['service:orderManagement:edit']"
          >
            {{ scope.row.technicianName ? "重新分配" : "分配" }}
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleCheck(scope.row)"
            v-hasPermi="['service:orderManagement:edit']"
            >查看
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleEdit(scope.row)"
            v-hasPermi="['service:orderManagement:edit']"
            >编辑
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['service:orderManagement:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <el-dialog
      title="分配"
      :visible.sync="showDistribution"
      width="500px"
      append-to-body
    >
      <el-form
        ref="distributionForm"
        :model="distributionForm"
        :rules="rules"
        label-width="80px"
      >
        <el-form-item label="选择小哥" prop="technicianId">
          <el-select
            v-model="distributionForm.technicianId"
            placeholder="请选择小哥"
          >
            <el-option
              v-for="item in technicianList"
              :key="item.userId"
              :label="item.nickName"
              :value="item.userId"
            ></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button
          :loading="distributionIng"
          type="primary"
          @click="distributionSubmit"
          >确 定</el-button
        >
        <el-button @click="distributionCancel">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 添加或修改订单管理对话框 -->
    <el-dialog
      :title="title"
      :visible.sync="open"
      width="60%"
      append-to-body
      @close="cancel"
    >
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <!--        <el-form-item label="用户id" prop="userId">-->
        <!--          <el-input v-model="form.userId" placeholder="请输入用户id" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="用户手机号" prop="userPhonenumber">-->
        <!--          <el-input-->
        <!--            v-model="form.userPhonenumber"-->
        <!--            placeholder="请输入用户手机号"-->
        <!--          />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="详细地址" prop="addrInfo">-->
        <!--          <el-input v-model="form.addrInfo" placeholder="请输入详细地址" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="用户车辆id" prop="userCarId">-->
        <!--          <el-input v-model="form.userCarId" placeholder="请输入用户车辆id" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="纬度" prop="lat">-->
        <!--          <el-input v-model="form.lat" placeholder="请输入纬度" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="经度" prop="lng">-->
        <!--          <el-input v-model="form.lng" placeholder="请输入经度" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="车主姓名" prop="ownerName">-->
        <!--          <el-input v-model="form.ownerName" placeholder="请输入车主姓名" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="车主联系方式" prop="ownerPhonenumber">-->
        <!--          <el-input-->
        <!--            v-model="form.ownerPhonenumber"-->
        <!--            placeholder="请输入车主联系方式"-->
        <!--          />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="预约时间" prop="appointTime">-->
        <!--          <el-date-picker-->
        <!--            clearable-->
        <!--            v-model="form.appointTime"-->
        <!--            type="datetime"-->
        <!--            value-format="yyyy-MM-dd HH:mm:ss"-->
        <!--            placeholder="请选择预约时间"-->
        <!--          >-->
        <!--          </el-date-picker>-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="服务id" prop="serveId">-->
        <!--          <el-input v-model="form.serveId" placeholder="请输入服务id" />-->
        <!--        </el-form-item>-->
        <!--                <el-form-item label="服务名称" prop="serveName">-->
        <!--                  <el-input v-model="form.serveName" placeholder="请输入服务名称" />-->
        <!--                </el-form-item>-->
        <!--        <el-form-item label="服务价格" prop="price">-->
        <!--          <el-input v-model="form.price" placeholder="请输入服务价格" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="支付价格" prop="payPrice">-->
        <!--          <el-input v-model="form.payPrice" placeholder="请输入支付价格" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="会员卡id" prop="cardSendId">-->
        <!--          <el-input v-model="form.cardSendId" placeholder="请输入会员卡id" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="优惠券id" prop="couponSendId">-->
        <!--          <el-input v-model="form.couponSendId" placeholder="请输入优惠券id" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="小哥id" prop="technicianId">-->
        <!--          <el-input v-model="form.technicianId" placeholder="请输入小哥id" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="订单状态" prop="status">-->
        <!--          <el-select v-model="form.status" placeholder="请选择订单状态">-->
        <!--            <el-option-->
        <!--              v-for="dict in dict.type.srv_order_status"-->
        <!--              :key="dict.value"-->
        <!--              :label="dict.label"-->
        <!--              :value="dict.value"-->
        <!--            ></el-option>-->
        <!--          </el-select>-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="洗车前照片" prop="beforeImg">-->
        <!--          <el-input-->
        <!--            v-model="form.beforeImg"-->
        <!--            type="textarea"-->
        <!--            placeholder="请输入内容"-->
        <!--          />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="洗车后照片" prop="afterImg">-->
        <!--          <el-input-->
        <!--            v-model="form.afterImg"-->
        <!--            type="textarea"-->
        <!--            placeholder="请输入内容"-->
        <!--          />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="干净程度打分" prop="cleanScore">-->
        <!--          <el-input-->
        <!--            v-model="form.cleanScore"-->
        <!--            placeholder="请输入干净程度打分"-->
        <!--          />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="服务态度打分" prop="attitudeScore">-->
        <!--          <el-input-->
        <!--            v-model="form.attitudeScore"-->
        <!--            placeholder="请输入服务态度打分"-->
        <!--          />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="备注" prop="remark">-->
        <!--          <el-input-->
        <!--            v-model="form.remark"-->
        <!--            type="textarea"-->
        <!--            placeholder="请输入内容"-->
        <!--          />-->
        <!--        </el-form-item>-->
        <template v-if="isEdit">
          <el-form-item label="车牌号" prop="carNo">
            <el-input v-model="form.carNo" placeholder="请输入车牌号" />
          </el-form-item>
          <el-form-item label="车辆品牌" prop="carBarnd">
            <el-input v-model="form.carBarnd" placeholder="请输入车辆品牌" />
          </el-form-item>
          <el-form-item label="车辆颜色" prop="carColor">
            <el-input v-model="form.carColor" placeholder="请输入车辆颜色" />
          </el-form-item>
          <el-form-item label="车辆型号" prop="carModel">
            <el-select
              v-model="form.carModel"
              placeholder="请选择车辆型号"
              clearable
            >
              <el-option
                v-for="dict in dict.type.srv_car_model"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="车主姓名" prop="ownerName">
            <el-input v-model="form.ownerName" placeholder="请输入车主姓名" />
          </el-form-item>
          <el-form-item label="车主电话" prop="ownerPhonenumber">
            <el-input
              v-model="form.ownerPhonenumber"
              placeholder="请输入车主电话"
            />
          </el-form-item>
          <el-form-item label="预约时间" prop="appointTime">
            <el-date-picker
              clearable
              v-model="form.appointTime"
              :picker-options="{
                step: '01:00',
                format: 'HH',
              }"
              type="datetime"
              value-format="yyyy-MM-dd HH"
              placeholder="请选择预约时间"
            />
          </el-form-item>
          <el-form-item label="小区名称" prop="cellName">
            <el-input v-model="form.cellName" placeholder="请输入小区名称" />
          </el-form-item>
          <el-form-item label="车库类型" prop="parkType">
            <el-input v-model="form.parkType" placeholder="请输入车库类型" />
          </el-form-item>
          <el-form-item label="车位号" prop="parkNo">
            <el-input v-model="form.parkNo" placeholder="请输入车位号" />
          </el-form-item>
          <el-form-item label="我方备注" prop="ourRemark">
            <el-input v-model="form.ourRemark" placeholder="请输入我方备注" />
          </el-form-item>
        </template>
        <el-descriptions title="基本信息" border>
          <el-descriptions-item label="订单状态">{{
            detail.orderManagement.statusName
          }}</el-descriptions-item>
          <el-descriptions-item label="订单编号">{{
            detail.orderManagement.id
          }}</el-descriptions-item>
          <el-descriptions-item label="服务名称">{{
            detail.orderManagement.serveName
          }}</el-descriptions-item>
          <template v-if="!isEdit">
            <el-descriptions-item label="车牌号">
              {{ detail.orderManagement.carNo }}
            </el-descriptions-item>
            <el-descriptions-item label="车辆品牌">
              {{ detail.orderManagement.carBarnd }}
            </el-descriptions-item>
            <el-descriptions-item label="车辆型号">
              <dict-tag
                :options="dict.type.srv_car_model"
                :value="detail.orderManagement.carBarnd"
              />
            </el-descriptions-item>
            <el-descriptions-item label="车辆颜色">
              {{ detail.orderManagement.carColor }}
            </el-descriptions-item>
            <el-descriptions-item label="车主姓名">
              {{ detail.orderManagement.ownerName }}
            </el-descriptions-item>
            <el-descriptions-item label="车主电话">
              {{ detail.orderManagement.ownerPhonenumber }}
            </el-descriptions-item>
            <el-descriptions-item label="小区名称">
              {{ detail.orderManagement.cellName }}
            </el-descriptions-item>
            <el-descriptions-item label="车库类型">
              {{ detail.orderManagement.parkType }}
            </el-descriptions-item>
            <el-descriptions-item label="车位号">
              {{ detail.orderManagement.parkNo }}
            </el-descriptions-item>
          </template>
          <el-descriptions-item
            v-if="detail.orderManagement.payType === '3'"
            label="积分"
          >
            {{ detail.orderManagement.payPrice }}
          </el-descriptions-item>
          <el-descriptions-item v-else label="价格">
            ￥ {{ detail.orderManagement.price }}
          </el-descriptions-item>
          <el-descriptions-item label="下单时间">
            {{ detail.orderManagement.createTime }}
          </el-descriptions-item>
          <el-descriptions-item label="详细位置" :span="3">
            {{ detail.orderManagement.addrInfo }}
          </el-descriptions-item>
        </el-descriptions>
        <el-descriptions border title="小哥信息" v-if="detail.technician">
          <el-descriptions-item label="头像">
            <el-image
              :src="detail.technician.avatar"
              style="width: 100px; height: 100px"
              :zoom-rate="1.2"
              :max-scale="7"
              :min-scale="0.2"
              :preview-src-list="[detail.technician.avatar]"
              fit="cover"
            ></el-image>
          </el-descriptions-item>
          <el-descriptions-item label="小哥姓名">
            {{ detail.technician.userName }}
          </el-descriptions-item>
          <el-descriptions-item label="小哥年龄">
            {{ detail.technician.age }}
          </el-descriptions-item>
        </el-descriptions>
        <el-descriptions title="下单人信息" border>
          <el-descriptions-item label="车主姓名">
            {{ detail.orderManagement.ownerName }}
          </el-descriptions-item>
          <el-descriptions-item label="车主电话">
            {{ detail.orderManagement.ownerPhonenumber }}
          </el-descriptions-item>
          <el-descriptions-item v-if="!isEdit" label="预约时间">
            {{ detail.orderManagement.appointTime }}
          </el-descriptions-item>
          <el-descriptions-item label="备注">
            {{ detail.orderManagement.remark }}
          </el-descriptions-item>
          <el-descriptions-item label="我方备注">
            {{ detail.orderManagement.ourRemark }}
          </el-descriptions-item>
        </el-descriptions>
        <el-descriptions title="费用明细" border>
          <el-descriptions-item
            v-if="detail.orderManagement.payType === '3'"
            label="车身标准清洗"
          >
            {{ detail.orderManagement.payPrice }} 积分
          </el-descriptions-item>
          <el-descriptions-item v-else label="车身标准清洗">
            ￥ {{ detail.orderManagement.price }}
          </el-descriptions-item>
          <el-descriptions-item v-if="detail.coupon" label="优惠减免">
            {{ detail.coupon.name }}{{ detail.coupon.price }}
          </el-descriptions-item>
          <el-descriptions-item v-if="detail.card" label="月卡抵扣">
            1 次
          </el-descriptions-item>
          <el-descriptions-item label="卡类型">
            <span v-if="detail.card.type === '0'">次卡</span>
            <dict-tag
              v-else
              :options="dict.type.srv_card_type"
              :value="detail.card.type"
            />
          </el-descriptions-item>
          <el-descriptions-item label="卡属性">
            <dict-tag
              :options="dict.type.srv_car_model"
              :value="detail.card.carModel"
            />
          </el-descriptions-item>
          <el-descriptions-item
            v-if="detail.orderManagement.payType === '3'"
            label="总价"
          >
            {{ detail.orderManagement.payPrice }} 积分
          </el-descriptions-item>
          <el-descriptions-item v-else label="总价">
            ￥ {{ detail.orderManagement.payPrice }}
          </el-descriptions-item>
        </el-descriptions>
        <el-descriptions
          border
          v-if="
            detail.orderManagement.beforeImg || detail.orderManagement.afterImg
          "
          title="车辆信息"
        >
          <el-descriptions-item label="洗车前" :span="3">
            <el-image
              v-for="(item, index) in detail.orderManagement.beforeImg"
              :src="item"
              style="width: 100px; height: 100px"
              :zoom-rate="1.2"
              :max-scale="7"
              :min-scale="0.2"
              :initial-index="index"
              :preview-src-list="detail.orderManagement.beforeImg"
              fit="cover"
            ></el-image>
          </el-descriptions-item>
          <el-descriptions-item
            :span="3"
            label="洗车后"
            v-if="detail.orderManagement.afterImg"
          >
            <el-image
              v-for="(item, index) in detail.orderManagement.afterImg"
              :src="item"
              style="width: 100px; height: 100px"
              :zoom-rate="1.2"
              :max-scale="7"
              :min-scale="0.2"
              :initial-index="index"
              :preview-src-list="detail.orderManagement.afterImg"
              fit="cover"
            ></el-image>
          </el-descriptions-item>
        </el-descriptions>
        <el-descriptions
          border
          v-if="
            detail.orderManagement.cleanScore ||
            detail.orderManagement.attitudeScore
          "
          title="评价信息"
        >
          <el-descriptions-item label="干净程度"
            >{{
              detail.orderManagement.cleanScore || 0
            }}
            分</el-descriptions-item
          >
          <el-descriptions-item label="服务态度"
            >{{
              detail.orderManagement.attitudeScore || 0
            }}分</el-descriptions-item
          >
        </el-descriptions>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button
          :loading="buttonLoading"
          v-if="isEdit"
          type="primary"
          @click="submitForm"
          >确 定</el-button
        >
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listOrderManagement,
  getOrderManagement,
  delOrderManagement,
  addOrderManagement,
  updateOrderManagement,
  distributionOrderManagement,
} from "@/api/service/orderManagement";
import { filter, get, map } from "lodash";
import { listUser } from "@/api/system/user";
import { parseTime } from "../../../utils/ruoyi";

export default {
  name: "OrderManagement",
  dicts: ["srv_order_status", "srv_car_model", "srv_card_type"],
  data() {
    return {
      showDistribution: false,
      distributionForm: {
        orderId: "",
        technicianId: "",
      },
      technicianList: [],
      distributionIng: false,
      // 按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 订单管理表格数据
      orderManagementList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 备注时间范围
      daterangeAppointTime: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userPhonenumber: undefined,
        deptId: undefined,
        deptName: undefined,
        appointTime: undefined,
        payType: undefined,
        status: undefined,
        params: {},
      },
      detail: {
        card: {},
        orderManagement: {},
      },
      isEdit: false,
      isDetail: true,
      payTypeList: {
        options: [
          { label: "现金支付", value: "1" },
          { label: "月卡抵消", value: "2" },
          { label: "积分支付", value: "3" },
        ],
        optionsMap: { 1: "现金支付", 2: "月卡抵消", 3: "积分支付" },
      },
      columns: [
        { key: 0, label: `订单编号`, visible: true },
        { key: 1, label: `用户手机号`, visible: true },
        { key: 2, label: `车辆信息`, visible: true },
        { key: 3, label: `预约时间`, visible: true },
        { key: 4, label: `支付方式`, visible: true },
        { key: 5, label: `支付价格`, visible: true },
        { key: 6, label: `服务名称`, visible: true },
        { key: 7, label: `小哥名称`, visible: true },
        { key: 8, label: `下单时间`, visible: true },
        { key: 9, label: `订单状态`, visible: true },
        { key: 10, label: `小区名称`, visible: true },
        { key: 11, label: `我方备注`, visible: true },
        { key: 12, label: `备注`, visible: true },
      ],
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        // id: [{ required: true, message: "订单id不能为空", trigger: "blur" }],
        // userId: [
        //   { required: true, message: "用户id不能为空", trigger: "blur" },
        // ],
        // userPhonenumber: [
        //   { required: true, message: "用户手机号不能为空", trigger: "blur" },
        // ],
        // deptId: [
        //   { required: true, message: "所属区域id不能为空", trigger: "change" },
        // ],
        // deptName: [
        //   {
        //     required: true,
        //     message: "所属区域名称不能为空",
        //     trigger: "change",
        //   },
        // ],
        // addrInfo: [
        //   { required: true, message: "详细地址不能为空", trigger: "blur" },
        // ],
        // userCarId: [
        //   { required: true, message: "用户车辆id不能为空", trigger: "blur" },
        // ],
        // lat: [{ required: true, message: "纬度不能为空", trigger: "blur" }],
        // lng: [{ required: true, message: "经度不能为空", trigger: "blur" }],
        // ownerName: [
        //   { required: true, message: "车主姓名不能为空", trigger: "blur" },
        // ],
        // ownerPhonenumber: [
        //   { required: true, message: "车主联系方式不能为空", trigger: "blur" },
        // ],
        // appointTime: [
        //   { required: true, message: "预约时间不能为空", trigger: "blur" },
        // ],
        // payType: [
        //   { required: true, message: "支付方式不能为空", trigger: "change" },
        // ],
        // serveId: [
        //   { required: true, message: "服务id不能为空", trigger: "blur" },
        // ],
        // serveName: [
        //   { required: true, message: "服务名称不能为空", trigger: "blur" },
        // ],
        // price: [
        //   { required: true, message: "服务价格不能为空", trigger: "blur" },
        // ],
        // payPrice: [
        //   { required: true, message: "支付价格不能为空", trigger: "blur" },
        // ],
        // cardSendId: [
        //   { required: true, message: "会员卡id不能为空", trigger: "blur" },
        // ],
        // couponSendId: [
        //   { required: true, message: "优惠券id不能为空", trigger: "blur" },
        // ],
        // technicianId: [
        //   { required: true, message: "小哥id不能为空", trigger: "blur" },
        // ],
        // status: [
        //   { required: true, message: "订单状态不能为空", trigger: "change" },
        // ],
        // beforeImg: [
        //   { required: true, message: "洗车前照片不能为空", trigger: "blur" },
        // ],
        // afterImg: [
        //   { required: true, message: "洗车后照片不能为空", trigger: "blur" },
        // ],
        // cleanScore: [
        //   { required: true, message: "干净程度打分不能为空", trigger: "blur" },
        // ],
        // attitudeScore: [
        //   { required: true, message: "服务态度打分不能为空", trigger: "blur" },
        // ],
        // cancelStatus: [
        //   { required: true, message: "取消状态不能为空", trigger: "change" },
        // ],
        // remark: [{ required: true, message: "备注不能为空", trigger: "blur" }],
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    parseTime,
    /** 查询订单管理列表 */
    getList() {
      this.loading = true;
      console.log({ daterangeAppointTime: this.daterangeAppointTime });
      if (
        null != this.daterangeAppointTime &&
        "" != this.daterangeAppointTime
      ) {
        this.queryParams.params["beginAppointTime"] =
          this.daterangeAppointTime[0];
        this.queryParams.params["endAppointTime"] =
          this.daterangeAppointTime[1];
      } else {
        this.queryParams.params = {};
      }
      listOrderManagement(this.queryParams).then((response) => {
        this.orderManagementList = map(response.rows, (item) => ({
          ...item,
          payTypeName: get(this.payTypeList.optionsMap, [item?.payType], ""),
        }));
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      console.log("cancel");
      this.open = false;
      this.isDetail = false;
      this.isEdit = false;
      this.detail = {
        card: {},
        orderManagement: {},
      };
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {};
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeAppointTime = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加订单管理";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.loading = true;
      this.reset();
      const id = row.id || this.ids;
      getOrderManagement(id).then((response) => {
        this.loading = false;
        this.form = response.data;
        this.open = true;
        this.title = "修改订单管理";
      });
    },
    // 分配
    handleDistribution(row) {
      listUser({
        pageNum: 1,
        status: "0",
        userType: "sys_user",
        pageSize: 9999,
      }).then((res) => {
        this.technicianList = map(
          filter(res?.rows, (v) => v?.userId.toString() !== "1"),
          (item) => {
            return {
              ...item,
            };
          }
        );
        this.showDistribution = true;
        this.distributionForm.orderId = row?.id;
      });
    },
    distributionCancel() {
      this.showDistribution = false;
      this.distributionIng = false;
    },
    distributionSubmit() {
      this.$refs.distributionForm.validate((valid) => {
        if (valid) {
          this.distributionIng = true;
          distributionOrderManagement(this.distributionForm)
            .then((res) => {
              this.$modal.msgSuccess("分配成功");
              this.distributionCancel();
              this.getList();
            })
            .finally(() => {
              this.distributionIng = false;
            });
        }
      });
    },
    // 编辑
    handleEdit(row) {
      this.isEdit = true;
      this.handleCheck(row);
    },
    // 查看
    handleCheck(row) {
      this.loading = true;
      this.reset();
      const id = row.id || this.ids;
      this.isDetail = true;
      getOrderManagement(id).then((response) => {
        this.loading = false;
        this.detail = {
          ...response?.data,
          card: {
            ...(response?.data?.card || {}),
          },
          orderManagement: {
            ...response.data?.orderManagement,
            statusName: {
              1: "待支付",
              2: "待服务",
              3: "服务中",
              4: "已完成",
              5: "已取消",
            }[response?.data?.orderManagement?.status],
            beforeImg: response?.data?.orderManagement?.beforeImg?.split(","),
            afterImg: response?.data?.orderManagement?.afterImg?.split(","),
            // ...response.data?.userCar,
          },
        };
        this.form = {
          ...response?.data?.orderManagement,
          // ...response.data?.userCar,
        };
        this.open = true;
        this.title = this.isEdit ? "编辑订单" : "查看订单";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          this.buttonLoading = true;
          if (this.form.id != null) {
            updateOrderManagement({
              ...this.form,
            })
              .then((response) => {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.isEdit = false;
                this.getList();
              })
              .finally(() => {
                this.buttonLoading = false;
              });
          } else {
            addOrderManagement(this.form)
              .then((response) => {
                this.$modal.msgSuccess("新增成功");
                this.open = false;
                this.isEdit = false;
                this.getList();
              })
              .finally(() => {
                this.buttonLoading = false;
              });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除订单管理编号为"' + ids + '"的数据项？')
        .then(() => {
          this.loading = true;
          return delOrderManagement(ids);
        })
        .then(() => {
          this.loading = false;
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {})
        .finally(() => {
          this.loading = false;
        });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "service/orderManagement/export",
        {
          ...this.queryParams,
        },
        `orderManagement_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
